// 类型断言
interface FOO {
    id: string;
    num: number;
}

let foo = {} as FOO;
foo.id = 'zs';
foo.num = 12;
// console.log(foo);

// window.foo = 1; // error
// (window as any).foo = 1

// function getCacheData(key: string): any {
//   return (window as any).cache[key];
// }

// 双重断言
interface Cat {
    run(): void;
}
interface Fish {
    swim(): void;
}

function testCat(cat: Cat) {
    return (cat as unknown) as Fish;
}

// // 类型断言 vs 类型转换§
// function toBoolean(something: any): boolean {
//   return something as boolean;
// }
// toBoolean(1);
// 返回值为 1
// 所以类型断言不是类型转换，它不会真的影响到变量的类型。
function toBoolean(something: any): boolean {
    return Boolean(something);
}

console.log(toBoolean(1));
// 返回值为 true
